package pad.stand.com.haidiyun.www.widget;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hdy.common.loadimage.LoadImageController;
import com.hdy.pad.service.ServiceController;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.io.File;
import java.io.IOException;

import pad.com.haidiyun.www.widget.SlipButton;
import pad.stand.com.haidiyun.www.R;
import pad.stand.com.haidiyun.www.base.AppManager;
import pad.stand.com.haidiyun.www.base.BaseApplication;
import pad.stand.com.haidiyun.www.common.Common;
import pad.stand.com.haidiyun.www.common.FileUtils;
import pad.stand.com.haidiyun.www.common.Mail;
import pad.stand.com.haidiyun.www.common.P;
import pad.stand.com.haidiyun.www.common.SharedUtils;
import pad.stand.com.haidiyun.www.common.TimeUtil;
import pad.stand.com.haidiyun.www.inter.UpdateIp;
import pad.stand.com.haidiyun.www.inter.UpdateMac;
import pad.stand.com.haidiyun.www.ui.CardValActivity;
import pad.stand.com.haidiyun.www.ui.OrderActivity;
import pad.stand.com.haidiyun.www.ui.ShowImages;
import pad.stand.com.haidiyun.www.utils.CopyFile;

public class CommonConfigPop extends MainBasePop{

    private Handler handler = new Handler() {
        public void dispatchMessage(android.os.Message msg) {
            switch (msg.what) {
                case -1:
                    NewDataToast.makeText("发送失败");
                    break;
                case 0:
                    NewDataToast.makeText("反馈成功");
                    break;
                case 1:
                    removeView();
                    break;
                case 2:
                    NewDataToast.makeText("数据清除完毕");
                    BaseApplication.application.resetApplication();
                    break;
                case 3:
                    NewDataToast.makeText("数据清除完毕");
                    BaseApplication.application.resetApplicationL();
                    break;
                case 4:
                    P.c("清楚完毕==============");
                    NewDataToast.makeText("数据清除完毕");
                    handler.sendEmptyMessage(5);
                    break;
                case 5:
                    BaseApplication.application.resetApplicationAll();
                    break;
                default:
                    break;
            }
        }

        ;
    };

    /**
     * 删除弹出框
     */
    private TextView login, wifi, con, con_img, close,
            delete_img, waite_view, ps_view, prepay_view, screen_view, update, cy_view,
            delete_adver, con_adver, change_skin, price_view, room_view, broad_view, change, tv_set_stand,
            giv_view, txt_view, limt_view, send_dev, fspace, dish_view, card_view, advert_view, reas_view, hall_view, time_view, tip_view, tv_language, tv_line, edit_price_view, gua_view, cd_view;
    private SlipButton waite_btn, ps_btn, prepay_btn, screen_btn, price_btn, room_btn, cy_btn, btn_set_stand,
            giv_btn, txt_btn, limt_btn, advert_btn, dish_btn, card_btn, hall_btn, time_btn, tip_btn, btn_line, btn_language, broad_btn, edit_price_btn, gua_btn, cd_btn;
    private SlipButton cook_btn;
    private long exitTime;
    private LinearLayout ll_stand, ll_back, ll_blank;
    private SharedUtils utils;

    public CommonConfigPop(Context context) {
        super(context);
        utils = new SharedUtils(Common.CONFIG);
    }

    private CommonSnyDataPop dataPop;
    private CommonSnyImagePop imagePop;
    private CommonSnyAdverPop videoPop;
    protected long lastClick;

    private void copyFile() {
        CopyFile cf = new CopyFile();
        try {
            File file = new File(Common.SOURCE_SKIN);
            if (!file.exists()) {
                file.mkdirs();
            }
            String sts[] = context.getAssets().list("skins");
            for (int i = 0; i < sts.length; i++) {
                cf.copyFile(context.getAssets().open("skins/" + sts[i]),
                        Common.SOURCE_SKIN + sts[i]);
                P.c("移动成功");
            }
        } catch (IOException e) {
            e.printStackTrace();
            P.c("移动失败");
        }
    }

    private void closeInit() {
        System.out.println("关闭了");
        try {

            AppManager.getAppManager().finishActivity(OrderActivity.class);
        } catch (Exception e) {

            e.printStackTrace();
        }
        try {
            AppManager.getAppManager().finishActivity(CardValActivity.class);
        } catch (Exception e) {

            e.printStackTrace();
        }
        try {
            AppManager.getAppManager().finishActivity(ShowImages.class);
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    public void showSheet() {
        addView(R.layout.setting_layout);
        configOpen();
    }

    private void configOpen() {
        ll_stand = (LinearLayout) mLayout.findViewById(R.id.ll_stand);
        ll_blank = (LinearLayout) mLayout.findViewById(R.id.ll_blank);
        login = (TextView) mLayout.findViewById(R.id.login);
        waite_btn = (SlipButton) mLayout.findViewById(R.id.waite_btn);
        ps_btn = (SlipButton) mLayout.findViewById(R.id.ps_btn);
        prepay_btn = (SlipButton) mLayout.findViewById(R.id.prepay_btn);
        waite_view = (TextView) mLayout.findViewById(R.id.waite_view);
        ps_view = (TextView) mLayout.findViewById(R.id.ps_view);
        broad_view = (TextView) mLayout.findViewById(R.id.broad_view);
        prepay_view = (TextView) mLayout.findViewById(R.id.prepay_view);
        change = (TextView) mLayout.findViewById(R.id.change);
        dish_btn = (SlipButton) mLayout.findViewById(R.id.dish_btn);
        cook_btn = (SlipButton) mLayout.findViewById(R.id.cook_btn);
        dish_view = (TextView) mLayout.findViewById(R.id.dish_view);

        broad_btn = (SlipButton) mLayout.findViewById(R.id.broad_btn);
//        table_view = (TextView) mLayout.findViewById(R.id.table_view);
        edit_price_view = (TextView) mLayout.findViewById(R.id.edit_price_view);
        edit_price_btn = (SlipButton) mLayout.findViewById(R.id.edit_price_btn);
        cy_view = (TextView) mLayout.findViewById(R.id.cy_view);
        cy_btn = (SlipButton) mLayout.findViewById(R.id.cy_btn);
        cd_view = (TextView) mLayout.findViewById(R.id.cd_view);
        cd_btn = (SlipButton) mLayout.findViewById(R.id.cd_btn);

        reas_view = (TextView) mLayout.findViewById(R.id.reas_view);
//        reas_btn = (SlipButton) mLayout.findViewById(R.id.reas_btn);
        card_view = (TextView) mLayout.findViewById(R.id.card_view);
        card_btn = (SlipButton) mLayout.findViewById(R.id.card_btn);
        advert_view = (TextView) mLayout.findViewById(R.id.advert_view);
        advert_btn = (SlipButton) mLayout.findViewById(R.id.advert_btn);
        screen_view = (TextView) mLayout.findViewById(R.id.screen_view);
        tv_line = (TextView) mLayout.findViewById(R.id.tv_line);
        screen_btn = (SlipButton) mLayout.findViewById(R.id.screen_btn);
        btn_line = (SlipButton) mLayout.findViewById(R.id.btn_line);
        price_btn = (SlipButton) mLayout.findViewById(R.id.price_btn);
        price_view = (TextView) mLayout.findViewById(R.id.price_view);
        limt_btn = (SlipButton) mLayout.findViewById(R.id.limt_btn);
        limt_view = (TextView) mLayout.findViewById(R.id.limt_view);
        hall_btn = (SlipButton) mLayout.findViewById(R.id.hall_btn);
        hall_view = (TextView) mLayout.findViewById(R.id.hall_view);
        time_btn = (SlipButton) mLayout.findViewById(R.id.time_btn);
        time_view = (TextView) mLayout.findViewById(R.id.time_view);
        tip_btn = (SlipButton) mLayout.findViewById(R.id.tip_btn);
        btn_language = (SlipButton) mLayout.findViewById(R.id.btn_language);
        tip_view = (TextView) mLayout.findViewById(R.id.tip_view);
        tv_language = (TextView) mLayout.findViewById(R.id.tv_language);
        gua_view = (TextView) mLayout.findViewById(R.id.gua_view);
        gua_btn = (SlipButton) mLayout.findViewById(R.id.gua_btn);
        room_btn = (SlipButton) mLayout.findViewById(R.id.room_btn);
        tv_set_stand = (TextView) mLayout.findViewById(R.id.tv_set_stand);
        btn_set_stand = (SlipButton) mLayout.findViewById(R.id.btn_set_stand);
        room_view = (TextView) mLayout.findViewById(R.id.room_view);
        send_dev = (TextView) mLayout.findViewById(R.id.send_dev);
        fspace = (TextView) mLayout.findViewById(R.id.fspace);
        giv_btn = (SlipButton) mLayout.findViewById(R.id.giv_btn);
        txt_btn = (SlipButton) mLayout.findViewById(R.id.txt_btn);
        giv_view = (TextView) mLayout.findViewById(R.id.giv_view);
        txt_view = (TextView) mLayout.findViewById(R.id.txt_view);
        change_skin = (TextView) mLayout.findViewById(R.id.change_skin);
        wifi = (TextView) mLayout.findViewById(R.id.wifi);
//        wifi.setTypeface(tf);
        String ddd = FileUtils.getDeviceIpStr();
        if (!ddd.equals("")) {
            wifi.setText("选择合适的WIFI" + "(" + FileUtils.getDeviceIpStr() + ")");
        }
        con = (TextView) mLayout.findViewById(R.id.con);
        String ip = utils.getStringValue("IP");
        if (!ip.equals("")) {
            con.setText("同步菜谱数据" + "(" + ip + ")");
            if (!utils.getStringValue("update_dish_time").equals("") && Build.MODEL.contains("H8002")) {
                con.setText("同步菜谱" + "(" + ip + ")" + " 空闲同步时间：" + utils.getStringValue("update_dish_time").replace(",", " - "));
            }
        }
        con_img = (TextView) mLayout.findViewById(R.id.con_img);
        delete_img = (TextView) mLayout.findViewById(R.id.delete_img);
//        con_video = (TextView) mLayout.findViewById(R.id.con_video);
        con_adver = (TextView) mLayout.findViewById(R.id.con_adver);
        close = (TextView) mLayout.findViewById(R.id.close);
        ll_back = (LinearLayout) mLayout.findViewById(R.id.ll_back);
//        delete = (TextView) mLayout.findViewById(R.id.delete);
        delete_adver = (TextView) mLayout.findViewById(R.id.delete_adver);
        update = (TextView) mLayout.findViewById(R.id.update);
        update.setText(update.getText() + "[版本号:"
                + BaseApplication.application.getVersion() + "]" + "     "
                + FileUtils.getDeviceId());
//        delete_video = (TextView) mLayout.findViewById(R.id.delete_video);
        if (utils.getBooleanValue("is_set_stand")) {
            btn_set_stand.setCheck(true);
            tv_set_stand.setText("隐藏九宫格独有设置项");
            ll_stand.setVisibility(View.VISIBLE);
            ll_blank.setVisibility(View.GONE);
        } else {
            btn_set_stand.setCheck(false);
            tv_set_stand.setText("显示九宫格独有设置项");
            ll_stand.setVisibility(View.GONE);
            ll_blank.setVisibility(View.VISIBLE);
        }
        btn_set_stand.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                utils.setBooleanValue("is_set_stand", CheckState);
                if (CheckState) {
                    tv_set_stand.setText("隐藏九宫格独有设置项");
                    ll_stand.setVisibility(View.VISIBLE);
                    ll_blank.setVisibility(View.GONE);
                } else {
                    tv_set_stand.setText("显示九宫格独有设置项");
                    ll_stand.setVisibility(View.GONE);
                    ll_blank.setVisibility(View.VISIBLE);
                }
                closeInit();
            }
        });
        if (utils.getBooleanValue("flip")) {
            change.setText("切换到基本版");
        } else {
            change.setText("切换到翻页版");
        }
        login.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                //配置ip及登录
                CommonLoginPop commonConfigPop = new CommonLoginPop(context, updateIp);
                commonConfigPop.showSheet();
            }
        });
        wifi.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                CommonWifiPop wifiPop = new CommonWifiPop(context, updateMac);
                wifiPop.showSheet();

            }
        });
        con.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                if (System.currentTimeMillis() - lastClick <= 2000) {
                    return;
                }
                lastClick = System.currentTimeMillis();
                if (utils.getBooleanValue("flip")) {
                    P.c("下载翻页");
                    Intent intentService = new Intent();
                    intentService.setAction("com.zed.download");
                    context.sendBroadcast(intentService);
                } else {
                    if (dataPop == null) {
                        dataPop = new CommonSnyDataPop(context, true, "同步菜品资源");
                        dataPop.showSheet();
                        dataPop = null;
                    }
                }
            }
        });
        con_img.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                if (System.currentTimeMillis() - lastClick <= 2000) {
                    return;
                }
                lastClick = System.currentTimeMillis();
                if (imagePop == null) {
                    imagePop = new CommonSnyImagePop(context, "同步菜品图片资源");
                    imagePop.showSheet();
                    imagePop = null;
                }

            }
        });
        delete_img.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                double_img_click();
            }
        });

//        delete_video.setOnClickListener(new OnClickListener() {
//
//            @Override
//            public void onClick(View arg0) {
//
//                double_video_click();
//            }
//        });
        delete_adver.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                double_adver_click();
            }
        });
        update.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                CommonApkPop apkPop = new CommonApkPop(context, "在线升级");
                apkPop.showSheet();
            }
        });
        update.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View arg0) {
                Intent intentService = new Intent();
                intentService.setAction(ServiceController.ACTION_VIEW_HIDE);
                context.sendBroadcast(intentService);
                Intent intent = new Intent(Settings.ACTION_SETTINGS);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                return true;
            }
        });
        ll_back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                handler.sendEmptyMessage(1);
            }
        });


        change_skin.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {

                if (utils.getBooleanValue("is_cy")) {
                    NewDataToast.makeText("请先恢复到默认界面");
                    return;
                }
                CommonSkinPop skinPop = new CommonSkinPop(context);
                skinPop.showSheet();
            }
        });
        if (!utils.getBooleanValue("is_edit_price")) {
            edit_price_btn.setCheck(true);
            edit_price_view.setText("允许临时菜改价");
        } else {
            edit_price_btn.setCheck(false);
            edit_price_view.setText("不允许临时菜改价");
        }
        if (utils.getBooleanValue("is_advert")) {
            advert_view.setText("广告模式");
            advert_btn.setCheck(true);
        } else {
            advert_view.setText("正常点餐");
            advert_btn.setCheck(false);
        }
        if (utils.getBooleanValue("is_cy")) {
            cy_btn.setCheck(true);
            cy_view.setText("三联界面");

        } else {
            cy_btn.setCheck(false);
            cy_view.setText("默认界面");
        }
        P.c("可配置值：" + utils.getBooleanValue("is_card"));
        if (utils.getBooleanValue("is_card")) {
            card_view.setText("启用电子支付");
            card_btn.setCheck(true);
        } else {
            card_view.setText("禁用电子支付");
            card_btn.setCheck(false);
        }

        if (utils.getBooleanValue("is_waite")) {
            waite_btn.setCheck(true);
//            dish_btn.setEnabled(true);
            waite_view.setText("服务员再次确认点餐模式");
        } else {
//            dish_btn.setEnabled(false);
            waite_btn.setCheck(false);
            waite_view.setText("顾客自主点餐模式");
        }
        if (utils.getBooleanValue("is_ps")) {
            ps_btn.setCheck(true);
            ps_view.setText("餐台选择必选密码模式");
        } else {
            ps_btn.setCheck(false);
            ps_view.setText("餐台选择无密码模式");
        }

        if (utils.getBooleanValue("is_gua")) {
            gua_view.setText("开启挂单");
            gua_btn.setCheck(true);
        } else {
            gua_view.setText("关闭挂单");
            gua_btn.setCheck(false);
        }
        if (utils.getBooleanValue("is_cd")) {
            cd_view.setText("开启补打");
            cd_btn.setCheck(true);
        } else {
            cd_view.setText("关闭补打");
            cd_btn.setCheck(false);
        }

        if (utils.getBooleanValue("is_print")) {
            broad_btn.setCheck(true);
            broad_view.setText("显示通知结账");
        } else {
            broad_btn.setCheck(false);
            broad_view.setText("隐藏通知结账");
        }
        if (utils.getBooleanValue("is_prepay")) {
            prepay_btn.setCheck(true);
            prepay_view.setText("先付费模式");
        } else {
            prepay_btn.setCheck(false);
            prepay_view.setText("后付费模式");
        }
        if (utils.getBooleanValue("is_dish")) {
            //
            dish_btn.setCheck(false);
            dish_view.setText("自助加菜");
        } else {
            dish_btn.setCheck(true);
            dish_view.setText("加菜确认");
        }
        if (utils.getBooleanValue("is_reas")) {
//            reas_btn.setCheck(true);
            cook_btn.setCheck(true);
            reas_view.setText("口味必选");
        } else {
            cook_btn.setCheck(false);
            reas_view.setText("直接点餐");
        }
        change.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (utils.getBooleanValue("flip")) {
                    utils.setBooleanValue("flip", false);
                } else {
                    utils.setBooleanValue("flip", true);
                }
                BaseApplication.application.resetApplicationAll();
            }
        });
        if (utils.getBooleanValue("screen_keep")) {
            screen_btn.setCheck(true);
            screen_view.setText("屏幕常亮模式");
        } else {
            screen_btn.setCheck(false);
            screen_view.setText("系统熄灭策略");
        }

        if (utils.getBooleanValue("isLine")) {
            btn_line.setCheck(true);
            tv_line.setText("恢复正常点餐");
        } else {
            btn_line.setCheck(false);
            tv_line.setText("切换排队点餐");
        }

        if (utils.getBooleanValue("is_price")) {
            price_btn.setCheck(true);
            price_view.setText("显示总价");
        } else {
            price_btn.setCheck(false);
            price_view.setText("隐藏总价");
        }

        if (utils.getBooleanValue("is_room")) {
            room_btn.setCheck(true);
            room_view.setText("显示包房菜");
        } else {
            room_btn.setCheck(false);
            room_view.setText("隐藏包房菜");
        }

        if (utils.getBooleanValue("is_hall")) {
            hall_btn.setCheck(true);
            hall_view.setText("隐藏大厅菜");
        } else {
            hall_btn.setCheck(false);
            hall_view.setText("显示大厅菜");
        }
        if (utils.getBooleanValue("is_time")) {
            time_btn.setCheck(true);
            time_view.setText("开启供应时间");
        } else {
            time_btn.setCheck(false);
            time_view.setText("关闭供应时间");
        }
        if (utils.getBooleanValue("is_tip")) {
            tip_btn.setCheck(true);
            tip_view.setText("开启下单提示");
        } else {
            tip_btn.setCheck(false);
            tip_view.setText("关闭下单提示");
        }
        if (utils.getBooleanValue("is_lan")) {
            btn_language.setCheck(true);
            tv_language.setText("切换中文");
        } else {
            btn_language.setCheck(false);
            tv_language.setText("切换英文");
        }

        if (utils.getBooleanValue("is_limit")) {
            limt_btn.setCheck(true);
            limt_view.setText("开启限制数量");
        } else {
            limt_btn.setCheck(false);
            limt_view.setText("取消限制数量");
        }
        if (utils.getBooleanValue("is_giv")) {
            giv_btn.setCheck(true);
            giv_view.setText("每行三菜");
        } else {

            giv_btn.setCheck(false);
            giv_view.setText("每行四菜");
        }
        if (utils.getBooleanValue("is_txt")) {
            txt_btn.setCheck(true);
            txt_view.setText("文字模式");
        } else {
            txt_btn.setCheck(false);
            txt_view.setText("图文模式");
        }

        File file = new File(Common.APK_LOG
                + TimeUtil.getTimeLog(System.currentTimeMillis()) + ".txt");

        fspace.setText("日志大小" + ((file != null && file.exists()) ? FileUtils.formatFileSize(file.length()) : "0kb"));
        send_dev.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                new Thread() {
                    @Override
                    public void run() {
                        super.run();
                        try {
                            Mail.send(handler, "bryant_liu24@126.com", "bryant_liu24@126.com", "smtp", "smtp.126.com", "liuzheng666");
                        } catch (Exception e) {
                            e.printStackTrace();
                            handler.sendEmptyMessage(-1);
                        }
                    }
                }.start();
            }
        });
        cy_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_cy", CheckState);
                if (CheckState) {
                    cy_view.setText("三联界面");
                } else {
                    cy_view.setText("默认界面");
                }
            }
        });
        gua_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_gua", CheckState);
                if (CheckState) {
                    gua_view.setText("开启挂单");
                } else {
                    gua_view.setText("关闭挂单");
                }
            }
        });
        cd_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_cd", CheckState);
                if (CheckState) {
                    cd_view.setText("开启补打");
                } else {
                    cd_view.setText("关闭补打");
                }
            }
        });
        cook_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_reas", CheckState);
                if (CheckState) {
                    reas_view.setText("口味必选");
                } else {
                    reas_view.setText("直接点菜");
                }
            }
        });
        edit_price_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_edit_price", CheckState);
                if (CheckState) {
                    edit_price_view.setText("允许临时菜改价");
                } else {
                    edit_price_view.setText("不允许临时菜改价");
                }
            }
        });
        advert_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_advert", CheckState);
                if (CheckState) {
                    advert_view.setText("广告模式");
                } else {
                    advert_view.setText("正常点餐");
                }
                closeInit();
            }
        });
        card_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_card", CheckState);
                if (CheckState) {
                    card_view.setText("启用电子支付");
                } else {
                    card_view.setText("禁用电子支付");
                }
            }
        });
        giv_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_giv", CheckState);
                if (CheckState) {
                    giv_view.setText("每行三菜");
                } else {
                    giv_view.setText("每行四菜");
                }
                closeInit();
            }
        });
        txt_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_txt", CheckState);
                if (CheckState) {
                    txt_view.setText("文字模式");
                } else {
                    txt_view.setText("图文模式");
                }
                closeInit();
            }
        });
        room_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_room", CheckState);
                if (CheckState) {
                    room_view.setText("显示包房菜");
                } else {
                    room_view.setText("隐藏包房菜");
                }
                closeInit();
            }
        });
        hall_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_hall", CheckState);
                if (CheckState) {
                    hall_view.setText("隐藏大厅菜");
                } else {
                    hall_view.setText("显示大厅菜");
                }
            }
        });
        time_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_time", CheckState);
                if (CheckState) {
                    time_view.setText("开启供应时间");
                } else {
                    time_view.setText("关闭供应时间");
                }
            }
        });
        tip_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_tip", CheckState);
                if (CheckState) {
                    tip_view.setText("开启下单提示");
                } else {
                    tip_view.setText("关闭下单提示");
                }
            }
        });
        btn_language.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_lan", CheckState);
                if (CheckState) {
                    tv_language.setText("切换中文");
                } else {
                    tv_language.setText("切换英文");
                }
                BaseApplication.application.resetApplicationAll();
            }
        });
        limt_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_limit", CheckState);
                if (CheckState) {
                    limt_view.setText("开启限制数量");
                } else {
                    limt_view.setText("关闭限制数量");
                }
            }
        });
        price_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_price", CheckState);
                if (CheckState) {
                    price_view.setText("显示总价");
                } else {
                    price_view.setText("隐藏总价");
                }
            }
        });
        screen_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("screen_keep", CheckState);
                if (CheckState) {
                    screen_view.setText("屏幕常亮模式");
                } else {
                    screen_view.setText("系统熄灭策略");
                }
                handler.sendEmptyMessage(5);
            }
        });
        btn_line.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("isLine", CheckState);
                if (CheckState) {
                    tv_line.setText("恢复正常点餐");
                } else {
                    tv_line.setText("切换排队点餐");
                }
            }
        });
        waite_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_waite", CheckState);
                if (CheckState) {
//                    dish_btn.setEnabled(true);
                    waite_view.setText("服务员再次确认点餐模式");
                } else {
//                    dish_btn.setEnabled(false);
//                    utils.setBooleanValue("is_dish", false);
                    waite_view.setText("顾客自主点餐模式");
                }
            }
        });
        ps_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_ps", CheckState);
                if (CheckState) {
                    ps_view.setText("餐台选择必选密码模式");
                } else {
                    ps_view.setText("餐台选择无密码模式");
                }
            }
        });
        broad_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_print", CheckState);
                if (CheckState) {
                    broad_view.setText("显示通知结账");
                } else {
                    broad_view.setText("隐藏通知结账");
                }
            }
        });
        prepay_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_prepay", CheckState);
                if (CheckState) {
                    prepay_view.setText("先付费模式");
                } else {
                    prepay_view.setText("后付费模式");
                }
            }
        });
        dish_btn.SetOnChangedListener(new SlipButton.OnChangedListener() {

            @Override
            public void OnChanged(boolean CheckState) {
                // TODO Auto-generated method stub
                utils.setBooleanValue("is_dish", CheckState);
                if (!CheckState) {
                    dish_view.setText("自助加菜");
                } else {
                    dish_view.setText("加菜确认");
                }
            }
        });
//        con_video.setOnClickListener(new OnClickListener() {
//
//            @Override
//            public void onClick(View arg0) {
//
//                if (System.currentTimeMillis() - lastClick <= 2000) {
//                    return;
//                }
//                lastClick = System.currentTimeMillis();
//                // NewDataToast.makeText(context, "暂不可用");
//
//                CommonSnyVideoPop videoPop = new CommonSnyVideoPop(context,
//                        "同步视频资源");
//                videoPop.showSheet();
//
//            }
//        });
        con_adver.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                if (System.currentTimeMillis() - lastClick <= 2000) {
                    return;
                }
                lastClick = System.currentTimeMillis();
                if (videoPop == null) {
                    videoPop = new CommonSnyAdverPop(context, "同步推广资源");
                    videoPop.showSheet();
                    videoPop = null;
                }

            }
        });
//        delete.setOnClickListener(new OnClickListener() {
//
//            @Override
//            public void onClick(View arg0) {
//
//                double_dish_click();
//            }
//        });
    }

    /**
     * 删除文件
     *
     * @param dir
     * @return
     */
    private synchronized boolean deleteDir(File dir) {
        if (!dir.exists()) {
            dir.mkdirs();
        }
        if (dir != null && dir.isDirectory()) {
            String[] children = dir.list();
            for (int i = 0; i < children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }
        return dir.delete();
    }

    /**
     * 删除菜品
     */
    private synchronized void double_dish_click() {
        if ((System.currentTimeMillis() - exitTime) > 1000) // System.currentTimeMillis()无论何时调用，肯定大于2000
        {
            exitTime = System.currentTimeMillis();
            NewDataToast.makeTextL("再按一次清除数据", 400);
        } else {
            exitTime = 0;
            LoadImageController.getInstance().clearMemory();
            new Thread() {
                @Override
                public void run() {
                    super.run();
                    // 删除数据
                    File file = new File(Common.DB_DIR + Common.DB_NAME);
                    if (file.exists()) {
                        file.delete();
                    }
                    deleteDir(new File(Common.ZIP));
                    LoadImageController.getInstance().clearDiskCache();
                    handler.sendEmptyMessage(3);
                }
            }.start();
        }

    }

    /**
     * 删除菜品图片
     */
    private synchronized void double_img_click() {
        if ((System.currentTimeMillis() - exitTime) > 1500) // System.currentTimeMillis()无论何时调用，肯定大于2000
        {
            exitTime = System.currentTimeMillis();
            NewDataToast.makeText("再按一次清除数据");
        } else {
            exitTime = 0;
            LoadImageController.getInstance().clearMemory();
            new Thread() {
                @Override
                public void run() {
                    super.run();
                    // 删除数据
                    /*
                     * File file = new File(Common.DB_DIR+Common.DB_NAME);
                     * if(file.exists()){ file.delete(); }
                     */
                    deleteDir(new File(Common.ZIP));
                    LoadImageController.getInstance().clearDiskCache();
                    ImageLoader.getInstance().clearDiscCache();
                    ImageLoader.getInstance().clearMemoryCache();
                    ImageLoader.getInstance().clearDiskCache();

                    handler.sendEmptyMessage(4);
                }
            }.start();
        }

    }

    /**
     * 删除视频
     */
    private synchronized void double_video_click() {
        if ((System.currentTimeMillis() - exitTime) > 1500) // System.currentTimeMillis()无论何时调用，肯定大于2000
        {

            exitTime = System.currentTimeMillis();
            NewDataToast.makeText("再按一次清除数据");
        } else {
            exitTime = 0;
            new Thread() {
                @Override
                public void run() {

                    super.run();
                    // 删除数据
                    deleteDir(new File(Common.SOURCE_VIDEO));
                    LoadImageController.getInstance().clearDiskCache();
                    handler.sendEmptyMessage(3);
                }
            }.start();
        }

    }

    /**
     * 删除视频
     */
    private synchronized void double_adver_click() {
        if ((System.currentTimeMillis() - exitTime) > 1500)
        // System.currentTimeMillis()无论何时调用，肯定大于2000
        {
            exitTime = System.currentTimeMillis();
            NewDataToast.makeText("再按一次清除数据");
        } else {
            exitTime = 0;
            new Thread() {
                @Override
                public void run() {
                    super.run();
                    // 删除数据
                    deleteDir(new File(Common.SOURCE_ADVER));
                    LoadImageController.getInstance().clearDiskCache();
                    LoadImageController.getInstance().clearDiskCache();
                    handler.sendEmptyMessage(3);
                }
            }.start();
        }

    }

    private UpdateIp updateIp = new UpdateIp() {

        @Override
        public void change(String ip) {
            con.setText("同步菜谱数据" + "(" + ip + ")");
        }
    };

    private UpdateMac updateMac = new UpdateMac() {

        @Override
        public void change(String mac) {
            wifi.setText("选择合适的wifi" + "(" + mac + ")");
        }
    };
}
